package com.example.testdemoutils.phone;

import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;

public class CheckPhoneNumber {
    public static void main(String[] args) {
        // 校验的号码
        String swissNumberStr = "+41044 668 18 00";
        // 获取 PhoneNumberUtil 实例
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        try {
            // 解析号码
            Phonenumber.PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "");
            // 校验号码
            boolean isVaild = phoneUtil.isValidNumber(swissNumberProto); // return true
            System.out.println("号码校验结果：" + isVaild);
        } catch (NumberParseException e) {
            System.err.println("号码解析异常: " + e.toString());
        }
    }
}
